package org.example.RabbitListener;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class SpringRabbitListener 
{
	//延迟队列，关键点在交换机设置delayed属性为true
	@RabbitListener(
			bindings = @QueueBinding(
					value = @Queue(name = "xiri.queue", durable = "true"),
					exchange = @Exchange(name = "xiri.direct", type = ExchangeTypes.DIRECT,delayed = "true"),
					key = "xiri.key"
			)
	)
	public void listener1(String mes) throws InterruptedException {
		System.out.println(LocalDateTime.now()+" 消费者接受消息："+mes);
	}
}
